import 'package:boss/color_constant.dart';
import 'package:boss/models/reback_order_list_data.dart';
import 'package:boss/models/takeout_order_list_data.dart';
import 'package:boss/textStyle/text_style.dart';
import 'package:boss/ui/page/takeoutManagement/page/takeoutDetail/widget/commodity_row.dart';
import 'package:boss/ui/widget/custom_divier.dart';
import 'package:hi_common/hi_common.dart';
import 'package:flutter/material.dart';

class ReturnCommodityList extends StatelessWidget {
  final RebackOrderItem data;

  const ReturnCommodityList({this.data});

  @override
  Widget build(BuildContext context) {
    if (data.refundMoneyOrderDetailList.length == 0) {
      return SizedBox();
    }

    return Column(
      children: <Widget>[
        Container(
          height: 80.w,
          padding: EdgeInsets.symmetric(horizontal: 20.w),
          alignment: Alignment.centerLeft,
          child: Text(
            '退款商品',
            style: TextStyleConstant().normal_3_28,
          ),
        ),
        CustomDivider(),
        for (final item in data.refundMoneyOrderDetailList)
          _CommodityRow(
            data: item.takeOutOrderDetail,
          ),
      ],
    );
  }
}

class _CommodityRow extends StatelessWidget {
  final TakeOutOrderDetails data;

  const _CommodityRow({Key key, this.data}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    List<Widget> children = [
      Container(
        padding: EdgeInsets.symmetric(vertical: 10.w),
        child: Row(
          children: <Widget>[
            Expanded(
              child: Text(data.titleWithSku),
              flex: 4,
            ),
            Expanded(
              child: Text('x${data.num}'),
              flex: 1,
            ),
            Expanded(
              child: TakeOutPriceText(
                price: data.commodityActualFee,
                color: ColorConstant.f594b,
              ),
            ),
          ],
        ),
      )
    ];

    if (data.takeOutOrderTastes.length > 0) {
      var tasteText = '';
      data.takeOutOrderTastes.forEach((item) {
        tasteText += item.tasteLabel;

        if (data.takeOutOrderTastes.last != item) {
          tasteText += ',';
        }
      });

      children.add(Container(
        padding: EdgeInsets.symmetric(vertical: 5.w),
        child: Text(
          '口味做法：$tasteText',
          style: TextStyleConstant().normal_3_24,
        ),
      ));
    }

    data.takeOutOrderMeterials?.forEach((item) {
      children.add(Container(
        padding: EdgeInsets.symmetric(vertical: 5.w),
        child: Row(
          children: <Widget>[
            Expanded(
              child: Text(
                item.meterialName,
                style: TextStyleConstant().normal_3_24,
              ),
              flex: 4,
            ),
            Expanded(
              child: Text(
                'x${item.unitNum}',
                style: TextStyleConstant().normal_3_28,
              ),
              flex: 1,
            ),
            Expanded(
              child: TakeOutPriceText(
                price: item.meterialInitialAmount,
                color: ColorConstant.f594b,
              ),
            ),
          ],
        ),
      ));
    });

    return Container(
      padding: EdgeInsets.symmetric(
        vertical: 15.w,
        horizontal: 30.w,
      ),
      decoration: BoxDecoration(border: Border(bottom: BorderSide(color: ColorConstant.e6e6, width: 1.px))),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisAlignment: MainAxisAlignment.start,
        children: children,
      ),
    );
  }
}
